﻿@{
    ViewBag.Title = "岗位管理";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-info">
                <div class="box-body">
                    <div class="table-responsive">
                        <div class="btn-group-sm" id="toolbar" role="group">
                            <a id="btnAdd" authorize="yes" class="btn btn-success" onclick="showForm('')"><i class="fa fa-plus"></i> 新增</a>
                            <div class="col-sm-3 pull-right">
                                <div class="input-group input-group-sm">
                                    <input type="text" id="keyWord" col="KeyWord" class="form-control" placeholder="请输入岗位编码或名称" />
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-primary" onclick="searchGrid()"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <table id="gridTable" class="table table-hover table-striped text-nowrap">
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<script>

    $(function () {
        initGrid();
    })
    function initGrid() {
        $('#gridTable').frameTable({
            url: '@Url.Action("GetPageListJson", "Position")',
            columns: [
                
                { field: 'Id', title: 'Id', visible: false },
                { field: 'Name', title: '岗位编码', halign: "center", align: "center" },
                { field: 'Code', title: '岗位名称', halign: "center", align: "center" },
                { field: 'Description', title: '岗位描述', halign: "center", align: "center" },
                { field: 'DisplayOrder', title: '显示顺序', halign: "center", align: "center" },
                {
                    field: 'EnabledMark', title: '用户状态', halign: "center", align: "center",
                    formatter: function (value, row, index) {
                        if (!!value) {
                            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="toggleStatus(\'' + row.Id + '\',false)"></i> ';
                        } else {
                            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="toggleStatus(\'' + row.Id + '\',true)"></i> ';
                        }
                    }
                },
                { field: 'CreatedOn', title: '创建时间', halign: "center", align: "center" },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a href="javascript:void(0);" authorize="yes" id="btnEdit" class="btn btn-primary btn-xs" onclick="showForm(\'' + row.Id + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                        actions.push('<a href="javascript:void(0);" authorize="yes" id="btnDelete" class="btn btn-danger btn-xs" onclick="deleteData(\'' + row.Id + '\')"><i class="fa fa-trash-o"></i> 删除</a>');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').frameTable('getPagination', params);
                var queryString = $('#toolbar').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').frameTable('search')
    }

    function showForm(id) {
        frame.openDialog({
            title: !!id ? '编辑岗位' :'新增岗位',
            content: '@Url.Content("/Manage/Position/Form")' + '?id=' + id,
            width: "480px",
            height: "350px",
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm();
            }
        });
    }

    function deleteData(id) {
        frame.confirm("确定要删除该岗位吗？", function () {
            frame.ajax({
                url: '@Url.Content("/Manage/Position/DeleteData")' + '?id=' + id,
                type: "post",
                success: function (obj) {
                    if (obj.success) {
                        frame.msgSuccess(obj.message);
                        searchGrid();
                    }
                    else {
                        frame.msgError(obj.message);
                    }
                }
            });
        });
    }
    function toggleStatus(id, result) {
        frame.confirm("确定要" + (result?"启用":"禁用") + "该岗位吗？", function () {
            frame.ajax({
                url: '@Url.Content("/Manage/Position/ChangeStatus")' + '?id=' + id,
                type: "post",
                success: function (obj) {
                    if (obj.success) {
                        frame.msgSuccess(obj.message);
                        searchGrid();
                    }
                    else {
                        frame.msgError(obj.message);
                    }
                }
            });
        });
    }
</script>